|
|
|
|
|
|
|
To see how pop-up menus work, select a menu item from the menu that you've created and set its Visible property to False. When this property is False, the only way you can access the Click routine for the menu item is by selecting the appropriate routine from the code editor's Object drop-down list. |
|
|
|
|
|
|
|
|
To display a pop-up menu, you need to invoke the form's PopUpMenu method. The syntax of this method is |
|
|
|
|
|
|
|
|
frmForm.PopUpMenu <menu item> |
|
|
|
|
|
|
|
|
where menu item is the Name of the top-level item that you want to display. Although you can use these pop-up menus in response to almost any action in your application, the excepted use is when the right mouse button is clicked. You can place the following code in the form's or object's MouseDown event: |
|
|
|
|
|
|
|
|
Private Sub <object>_MouseDown(Button As Integer, Shift As Integer,
X As Single, Y As Single)
If Button = vbRightButton Then
frmMain.PopUpMenu <menu item> End If
End Sub |
|
|
|
|
|
|
|
|
This code will display a pop-up menu at the mouse pointer whenever users right-click. Now add this code to the form's MouseDown event, remembering to change the references to the form name and the menu item name. Run the application and right-click anywhere on the form; the pop-up menu should appear. |
|
|
|
|
|
|
|
|
What does negotiating menus really do for you? When you're creating an MDI application, you must take care to create your menus properly. If any of the child forms have menus of their own, you need to decide which menu bar will be displayed by your application. Whenever a child form has a menu associated with it, its menu will replace the parent form menu when the child form is displayed. |
|
|
|
|
|
|
|
|
You can deal with menus in an MDI application in only two ways: |
|
|
|
|
|
|
|
|
Add all the required functions to each child form's menu. That way, whichever menu is displayed will have the correct menu items on it. |
|
|
|
|
|
|
|
|
Place all the different menu items on the main parent menu and display only the ones required at any given moment (preferred). This process is handled by using the menu item's Visible property to show or hide the item. When a child form is displayed, its Form_Load routine would set the Visible properties of the required menu items to True and the other menu items to False. |
|
|
|
|
|